<!DOCTYPE html>
<html class="x-admin-sm">

    <head>
        <meta charset="UTF-8">
        <title>欢迎页面-X-admin2.2</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="/static/css/font.css">
        <link rel="stylesheet" href="/static/css/xadmin.css">
        <script src="/static/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="/static/js/xadmin.js"></script>
        <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>

    <body>
        <div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">首页</a>
                <a href="">演示</a>
                <a>
                    <cite>导航元素</cite></a>
            </span>
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
                <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
            </a>
        </div>
        <div >
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <!--class="layui-form layui-col-space5" id="userSearch"-->
                            <form  class="layui-form layui-form-pane"  action="">
                                <div class="layui-inline layui-show-xs-block">
                                    <input class="layui-input" autocomplete="off" placeholder="开始日" name="start" id="start"></div>
                                <div class="layui-inline layui-show-xs-block">
                                    <input class="layui-input" autocomplete="off" placeholder="截止日" name="end" id="end"></div>
                                <div class="layui-inline layui-show-xs-block">
                                    <input type="text" name="empName" placeholder="请输入用户名" autocomplete="off" class="layui-input"></div>
                                <div class="layui-inline layui-show-xs-block">
                                    <button class="layui-btn" lay-submit="" lay-filter="searchSubmit">
                                        <i class="layui-icon">&#xe615;</i></button>
                                </div>
                            </form>
                        </div>
                        <table class="layui-table" id="valueTable" lay-filter="studentManage">

                        </table>

                        <script type="text/html" id="toolbar">
                            <xblock>
                                <a class="layui-btn layui-btn-mini" lay-event="add"><i class="layui-icon"></i>添加</a>
                            </xblock>
                            <xblock>
                                <a class="layui-btn layui-btn-mini" href="emp-del.html">回收站</a>
                            </xblock>
                        </script>
                        <script type="text/html" id="barDemo">
                            <a class="layui-btn layui-btn-mini" lay-event="edit">编辑</a>
                            <a class="layui-btn layui-btn-mini layui-btn-danger" lay-event="del">删除</a>

                        </script>
                    </div>
                </div>
            </div>
        </div>
    </body>

    <script>
        layui.use(['form','laydate'], function(){
            var form = layui.form ,layer = layui.layer
                ,laydate = layui.laydate;
            //日期
            laydate.render({
                elem: '#start'
            });
            laydate.render({
                elem: '#end'
            });
            //TODO 数据校验
            form.on('submit(searchSubmit)', function(data){
                load(data);
                return false;
            });
        });
        var form;
        var table;
        layui.use('table', function () {
            // 很重要,初始化
            table = layui.table, form = layui.form;
            table.render({
                elem: '#valueTable'  //要和table标签ID一致
                , url: '/contact'
                , id: 'testReload'
                , toolbar:'#toolbar'
                , page: true
                , limit: 10
                ,loading: true
                ,cols: [[
                    {type:'numbers',title:'序号',align:'center', width:40} // 自增序号
                    ,{field: 'contactId', title: '跟踪ID', align: 'center', width: 70}
                    , {field: 'way', title:'途径',width: 80, align: 'center'}
                    , {field: 'content', title: '内容', align: 'center', width: 40}
                    , {field: 'customerName', templet:'<div>{{d.customers[0].customerName}}</div>',title: '所属客户', align: 'center', width: 80}
                    , {field: 'empName', templet:'<div>{{d.employees[0].empName}}</div>',title: '所属员工', align: 'center', width: 80}
                    ,{fixed: 'right', width: 150, align: 'center', toolbar: '#barDemo', title: '操作'}
                ]]
                , done: function (res, curr, count) {
                    $("[data-field='isOrders']").children().each(function(){
                        if($(this).text()=='0'){
                            $(this).text("未下单")
                        }else if($(this).text()=='1'){
                            $(this).text("已下单")
                        }
                    });
                    console.log(res.data);
                }
            });

            table.on('tool(studentManage)', function(obj){
                var data = obj.data;
                if(obj.event === 'detail'){
                    layer.msg('ID：'+ data.id + ' 的查看操作');
                } else if(obj.event === 'del'){
                    layer.confirm('确定删除吗', function(index){
                        console.log(data);
                        $.ajax({
                            url: "/emp/del/"+data.empId,
                            type: "DELETE",
                            //data:{"uvid":data.id,"memthodname":"deleteuv","aid":data.aid},
                            //dataType: "json",
                            success: function(data){
                                if(data.state==1){
                                    obj.del();
                                    layer.close(index);
                                    layer.msg("删除成功", {icon: 6});
                                }else{
                                    layer.msg("删除失败", {icon: 5});
                                }
                            }

                        });
                    });
                } else if(obj.event === 'edit'){

                    editStudent(data);
                }
            });

            table.on('toolbar(studentManage)', function(obj){
                var data = obj.data;
                if (obj.event === 'add'){
                    addStudent(data)
                }
            });

        });

        //userList.js
        //编辑用户
        function editStudent(data){
            var index = layui.layer.open({
                title : "编辑",
                type : 2,
                content : "emp-edit.html",//弹出层页面
                area: ['450px', '500px'],
                success : function(layero, index){
                    var body = layui.layer.getChildFrame('body', index);
                    if(data){
                        // 取到弹出层里的元素，并把编辑的内容放进去
                        body.find("#empId").val(data.empId)
                        body.find("#empName").val(data.empName);
                        body.find("#sex").val(data.sex);
                        body.find("#age").val(data.age);
                        body.find("#phone").val(data.phone);
                        body.find("#address").val(data.address);
                        body.find("#roleName").val(data.roleId);
                        // 根据id选择那一项
                        body.find("#roleName option").eq(data.roleId).attr("selected");
                        // 记得重新渲染表单
                        form.render();
                    }
                    setTimeout(function(){
                        layui.layer.tips('点击此处返回员工列表', '.layui-layer-setwin .layui-layer-close', {
                            tips: 3
                        });
                    },500)
                }
            })
            //layui.layer.full(index);//设置弹出层布满窗口
            //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
            $(window).on("resize",function(){
                //layui.layer.full(window.sessionStorage.getItem("index"));
            })
        }

        function addStudent(data){
            var index = layui.layer.open({
                title : "添加员工",
                type : 2,
                content : "customer-add.html",//弹出层页面
                area: ['450px', '500px'],
                success : function(layero, index){
                    var body = layui.layer.getChildFrame('body', index);
                    if(data){
                        form.render();
                    }
                    setTimeout(function(){
                        layui.layer.tips('点击此处返回客户列表', '.layui-layer-setwin .layui-layer-close', {
                            tips: 3
                        });
                    },500)
                }
            })
            $(window).on("resize",function(){
            })
        }
    </script>
    <script>var _hmt = _hmt || []; (function() {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();</script>

</html>